home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 June: Reference Library / Dev.CD Jun 96 RL / Dev.CD Jun 96 RL.toast / Technical Documentation / develop / develop Issue 24 / develop Issue 24 code / Scriptable Database 1.0a15 / Foundation / EntireContents.cp < prev    next >
Encoding:
Text File  |  1996-02-19  |  9.9 KB  |  308 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        EntireContents.c
  3.  
  4.     Contains:    The 'entire contents' property is similar to 'every item', but
  5.                 it includes every item deep inside the specified container
  6.                 (e.g. 'entire contents of startup disk' returns every item on
  7.                 the startup disk, not just the items at the root of the startup
  8.                 disk)
  9.                 
  10.     Written by:    Greg Anderson
  11.  
  12.     Copyright:    © 1993-1995 by Apple Computer, Inc., all rights reserved.
  13.  
  14.         <14>     6/15/95    ga        
  15.     
  16. */
  17.  
  18. #ifdef MWTRACEBACKTABLES
  19. #pragma traceback on
  20. #endif
  21.  
  22. #include "EntireContents.h"
  23.  
  24. #include "AbstractSearchSpec.h"
  25. #include "MarkToken.h"
  26.  
  27. #include <AEObjects.h>
  28. #include <AEPackObject.h>
  29. #include <AERegistry.h>
  30. #include <AppleEvents.h>
  31.  
  32. // #include "FinderRegistry.h"
  33.  
  34. #include "Exceptions.h"
  35.  
  36. //
  37. // For CopyMemory
  38. //
  39. #include "AbstractData.h"
  40.  
  41.  
  42. //========================================================================================
  43. // CLASS TEntireContents
  44. //========================================================================================
  45.  
  46.  
  47. #pragma segment ObjectResident
  48. ImplementSmallClassData(TEntireContents, clEntireContents);
  49.  
  50. #pragma segment Foundation
  51.  
  52. //----------------------------------------------------------------------------------------
  53. // TEntireContents::TEntireContents: 
  54. //----------------------------------------------------------------------------------------
  55. TEntireContents::TEntireContents()
  56.     {
  57.     fRootItem = nil;
  58.     } // TEntireContents::TEntireContents 
  59.  
  60. //----------------------------------------------------------------------------------------
  61. // TEntireContents::~TEntireContents: 
  62. //----------------------------------------------------------------------------------------
  63. TEntireContents::~TEntireContents()
  64.     {
  65.     } // TEntireContents::~TEntireContents 
  66.  
  67. //----------------------------------------------------------------------------------------
  68. // TEntireContents::IEntireContents: 
  69. //----------------------------------------------------------------------------------------
  70. void TEntireContents::IEntireContents(TAbstractScriptableObject* rootIcon)
  71.     {
  72.     fRootItem = rootIcon;
  73.  
  74.     TProxyToken::IProxyToken();
  75.     } // TEntireContents::IEntireContents 
  76.  
  77. //----------------------------------------------------------------------------------------
  78. // TEntireContents::ObjectClass:
  79. //----------------------------------------------------------------------------------------
  80. DescType TEntireContents::ObjectClass(const TAETransaction& t, Boolean recordedClass /*= false*/)
  81.     {
  82.     if(recordedClass)
  83.         return Inherited::ObjectClass(t, recordedClass);
  84.     else
  85.         return cEntireContents;
  86.     } // TEntireContents::ObjectClass 
  87.  
  88. //----------------------------------------------------------------------------------------
  89. // TEntireContents::DerivedFromOSLClass: 
  90. //----------------------------------------------------------------------------------------
  91. Boolean TEntireContents::DerivedFromOSLClass(const TAETransaction& t, DescType objectClass)
  92.     {
  93.     return (objectClass == cEntireContents) || (Inherited::DerivedFromOSLClass(t, objectClass));
  94.     } // TEntireContents::DerivedFromOSLClass 
  95.  
  96. //----------------------------------------------------------------------------------------
  97. // TEntireContents::PropertyAppliesToProxy: 
  98. //----------------------------------------------------------------------------------------
  99. Boolean TEntireContents::PropertyAppliesToProxy(DescType propertyName)
  100.     {
  101.     return ((propertyName == kAEAll) || (Inherited::PropertyAppliesToProxy(propertyName)));
  102.     } // TEntireContents::PropertyAppliesToProxy 
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // TEntireContents::ElementIterator
  106. //----------------------------------------------------------------------------------------
  107. TAbstractObjectIterator* TEntireContents::ElementIterator(const TAETransaction&)
  108.     {
  109.     return new TDeepIterator(fRootItem);
  110.     } // TEntireContents::ElementIterator
  111.  
  112.  
  113. //========================================================================================
  114. // Class TDeepIterator
  115. //========================================================================================
  116.  
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // TDeepIterator::~TDeepIterator
  120. //----------------------------------------------------------------------------------------
  121. TDeepIterator::~TDeepIterator()
  122. {
  123.     this->ClearIteratorStack();
  124.     if(fIterStack)
  125.         delete [] fIterStack;
  126.     fIterStack = nil;
  127.     fStackSize = 0;
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. // TDeepIterator::TopIterator
  132. //----------------------------------------------------------------------------------------
  133. TAbstractObjectIterator* TDeepIterator::TopIterator() const
  134. {
  135.     TAbstractObjectIterator* iter = nil;
  136.     if(fItersOnStack)
  137.         {
  138.         iter = fIterStack[fItersOnStack - 1];
  139.         }
  140.     
  141.     return iter;
  142. }
  143.  
  144. //----------------------------------------------------------------------------------------
  145. // TDeepIterator::PopIterator
  146. //----------------------------------------------------------------------------------------
  147. TAbstractObjectIterator* TDeepIterator::PopIterator()
  148. {
  149.     TAbstractObjectIterator* iter = TopIterator();
  150.     if(iter != nil)
  151.         --fItersOnStack;
  152.     
  153.     return iter;
  154. }
  155.  
  156. //----------------------------------------------------------------------------------------
  157. // TDeepIterator::PushIterator
  158. //----------------------------------------------------------------------------------------
  159. void TDeepIterator::PushIterator(TAbstractObjectIterator* iter)
  160. {
  161.     if(fItersOnStack >= fStackSize)
  162.     {
  163.         long newStackSize = fStackSize << 1;
  164.         if(newStackSize == 0)
  165.             newStackSize = 8;
  166.         
  167.         //
  168.         // ◊ could use ListTemplate.h here
  169.         //
  170.         TAbstractObjectIterator** newStack = new TAbstractObjectIterator*[newStackSize];
  171.         if(fIterStack != nil)
  172.         {
  173.             CopyMemory(fIterStack, newStack, fStackSize * sizeof(Ptr)); // memcpy(newStack, fIterStack, fStackSize * sizeof(Ptr));
  174.             delete [] fIterStack;
  175.         }
  176.         fIterStack = newStack;
  177.         fStackSize = newStackSize;
  178.     }
  179.     
  180.     fIterStack[fItersOnStack] = iter;
  181.     ++fItersOnStack;
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. // TDeepIterator::ClearIteratorStack
  186. //----------------------------------------------------------------------------------------
  187. void TDeepIterator::ClearIteratorStack()
  188. {
  189.     TAbstractObjectIterator* iter = nil;
  190.     
  191.     while((iter = this->PopIterator()) != nil)
  192.         iter->Release();
  193. }
  194.  
  195. //----------------------------------------------------------------------------------------
  196. // TDeepIterator::Reset
  197. //----------------------------------------------------------------------------------------
  198. void TDeepIterator::Reset(const TAETransaction& t, Boolean iterationDirection /* = kForwardIteration */)
  199. {
  200.     this->ClearIteratorStack();
  201.     fDirection = iterationDirection;
  202.     this->PushSubtree(t, fRootItem);
  203. }
  204.  
  205. //----------------------------------------------------------------------------------------
  206. // TDeepIterator::PushSubtree
  207. //----------------------------------------------------------------------------------------
  208. void TDeepIterator::PushSubtree(const TAETransaction& t, TAbstractScriptableObject* fromWhere)
  209. {
  210.     TAbstractObjectIterator* iter = fromWhere->ElementIterator(t);
  211.     while(iter != nil)
  212.     {
  213.         iter->Reset(t, fDirection);
  214.         if(iter->More(t))
  215.         {
  216.             this->PushIterator(iter);
  217.             TAbstractScriptableObject* current = iter->Current(t);
  218.             iter = current->ElementIterator(t);
  219.             current->DisposeDesignator();
  220.         }
  221.         else
  222.         {
  223.             iter->Release();
  224.             iter = nil;
  225.         }
  226.     }
  227. }
  228.  
  229. //----------------------------------------------------------------------------------------
  230. // TDeepIterator::More
  231. //----------------------------------------------------------------------------------------
  232. Boolean TDeepIterator::More(const TAETransaction& t) const
  233. {
  234.     TAbstractObjectIterator* iter = TopIterator();
  235.     
  236.     //
  237.     // In truth, we expect iter->More() to always be true; if it
  238.     // isn't, then we should have removed 'iter' from the stack.
  239.     //
  240.     return iter ? iter->More(t) : false;
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. // TDeepIterator::Next
  245. //----------------------------------------------------------------------------------------
  246. void TDeepIterator::Next(const TAETransaction& t)
  247. {
  248.     TAbstractObjectIterator* iter = TopIterator();
  249.  
  250.     if(iter != nil)
  251.     {
  252.         iter->Next(t);
  253.         while(iter && (iter->More(t) == false))
  254.         {
  255.             this->PopIterator();
  256.             iter = TopIterator();
  257.             if(iter != nil)
  258.                 iter->Next(t);
  259.         }
  260.         if(iter != nil)
  261.         {
  262.             TAbstractScriptableObject* current = iter->Current(t);
  263.             this->PushSubtree(t, current);
  264.             current->DisposeDesignator();
  265.         }
  266.     }
  267. }
  268.  
  269. //----------------------------------------------------------------------------------------
  270. // TDeepIterator::Current
  271. //----------------------------------------------------------------------------------------
  272. TAbstractScriptableObject* TDeepIterator::Current(const TAETransaction& t)
  273. {
  274.     TAbstractObjectIterator* iter = TopIterator();
  275.  
  276.     return iter ? iter->Current(t) : nil;
  277. }
  278.  
  279. //----------------------------------------------------------------------------------------
  280. // TDeepIterator::AccessBySearchSpec
  281. //----------------------------------------------------------------------------------------
  282. void TDeepIterator::AccessBySearchSpec(const TAETransaction& t, TAbstractCollector* collector, DescType desiredClass, TAbstractSearchSpec* searchSpec)
  283. {
  284.     TAbstractObjectIterator* iter = fRootItem->ElementIterator(t);
  285.     if(iter != nil)
  286.     {
  287.         //
  288.         // Tell the iterator to do a deep search; results will
  289.         // be accumulated into the collector object.
  290.         //
  291.         iter->SearchDeep(t, collector, desiredClass, searchSpec);
  292.         iter->Release();
  293.     }
  294. } // TDeepIterator::AccessBySearchSpec
  295.  
  296. //----------------------------------------------------------------------------------------
  297. // TDeepIterator::SearchDeep
  298. //----------------------------------------------------------------------------------------
  299. void TDeepIterator::SearchDeep(const TAETransaction&, TAbstractCollector* /*collector*/, DescType /*desiredClass*/, TAbstractSearchSpec* /*searchSpec*/)
  300. {
  301.     //
  302.     // It should be impossible to get here
  303.     //
  304.     FailErr(errAEEventNotHandled);
  305. } // TDeepIterator::SearchDeep
  306.  
  307. #pragma segment CFrontCruft
  308.